<?php


namespace app\data\controller\api\auth;


use app\admin\controller\api\Upload;
use app\data\controller\api\Auth;

class Release extends Auth
{
    /**
     * 写文章
     */
    public function article(){
        /*$data = $this->_vali([
            'name.require'      => '请输入新闻标题',
            'content.require'   => '请输入新闻内容'
        ]);*/
        //新闻标题 name 新闻内容 content 内外仓 type 图片 images 视频 video
        $data = input('post.');
        unset($data['token']);
        $data['publisher'] = $this->mid;

        if (!empty($data['images'])){
            $data['images'] = json_encode($data['images']);
        }

        $result = $this->app->db->name('data_news_item')->insert($data);
        if ($result){
            $this->success('发布成功');
        }else{
            $this->error('发布失败');
        }
    }

    /**
     * 草稿箱
     */
    public function drafts(){
        //新闻标题 name 新闻内容 content 内外仓 type 图片 images 视频 video
        $data = input('post.');
        unset($data['token']);
        $data['publisher'] = $this->mid;

        if (!empty($data['images'])){
            $data['images'] = json_encode($data['images']);
        }

        $result = $this->app->db->name('data_news_item_drafts')->insert($data);
        if ($result){
            $this->success('存草稿箱成功');
        }else{
            $this->error('存储失败');
        }
    }

    /**
     * 发图片

    public function picture(){
        $data = input('post.');
        unset($data['token']);
        $data['publisher'] = $this->mid;
        $result = $this->app->db->name('data_news_item')->insert($data);
        if ($result){
            $this->success('发布成功');
        }else{
            $this->error('发布失败');
        }
    }*/

}